package com.example.banksys;

import DataBase.DBMsg;
import DataBase.myDB;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.Pane;

import java.sql.SQLException;

public class EditController {
    public Label ID ;
    public TextField Organization;
    public TextField Department;
    public TextField Type;
    public Pane mainPane;
    public Button confirm;
    public TextField name;
    public String namestr,orgstr,depstr,typstr;
    public Button reset;

    public void initialize(){
        namestr= "";
        orgstr="";
        depstr="";
        typstr="";
    }

    public void clear(){
        name.setText(namestr);
        Organization.setText(orgstr);
        Department.setText(depstr);
        Type.setText(typstr);
    }

    public void submit() throws SQLException {
        long empID=Long.parseLong(ID.getText());
        myDB database=new myDB("banksystem");
        String sql="update employee set department ='"+Department.getText()+"', organization='"+Organization.getText()+"', name='"+name.getText()+"', type='"+Type.getText()+"'where employee_ID="+empID;
        database.getStatement().execute(sql);
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.titleProperty().set("信息");
        alert.headerTextProperty().set("修改成功！");
        alert.showAndWait();
        mainPane.getScene().getWindow().hide();
        EmployeeManageController.needRefresh.set(true);
    }
}
